<!--
 * @Description: Stay hungry，Stay foolish
 * @Author: ''
 * @Date: 2023-10-15 17:44:34
 * @LastEditTime: 2023-10-15 18:05:53
 * @LastEditors: ''
-->
<template>
  <div>

    <e-input type="textarea" v-model="value" />
    <e-button @click="handleCopy">复制</e-button>
  </div>
</template>

<script setup>
import {ref,getCurrentInstance,onMounted} from "vue"
let value=ref('Hello');
let useClip=getCurrentInstance().appContext.config.globalProperties.$Copy
const source = ref('Hello')
const { text, copy, copied, isSupported } = useClip({source:value,
  read: false,
  legacy: true}
)
console.log(getCurrentInstance().appContext.config.globalProperties)
const handleCopy= async ()=>{
  
  const { text, copy, copied, isSupported } = useClip({source:value.value,
    read: false,
    legacy: true}
  )
  console.log('useClip',text, copy, copied, isSupported)
  if (!isSupported) {
    vm.value.$Message.error({
      content: "复制失败",
      background: true,
    });
    return
  }
  try {
    await copy();
    vm.value.$Message.success({
      content: `复制成功${text.value},${copied.value}`,
      background: true,
    });
  } catch (e) {
    vm.value.$Message.error(e.message);
  }

}

let vm =ref()
onMounted(() => {
  vm.value = getCurrentInstance().proxy;
})


</script>

<style>

</style>